package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import tech.aistar.entity.Film;
import tech.aistar.service.FilmService;

import java.util.List;

/**
 * 本类用来演示
 *
 * @author success
 * @date 2023/3/5 17:41:11
 */
@RestController
@RequestMapping( "/film")
public class FilmController {
    @Autowired
    private FilmService filmService;

    //通过id得到用户信息
    @RequestMapping(value = "/getFilm/{id}")
    public String getFilm(@PathVariable int id){
        return filmService.getFilm(id).toString();
    }

    //通过id删除用户信息
    @RequestMapping(value = "/delete")
    public String delete(int id){
        int result = filmService.delete(id);
        if(result >= 1){
            return "删除成功！";
        }else{
            return "删除失败！";
        }
    }

    //更改用户信息
    @RequestMapping(value = "/update")
    public String update(Film film){
        int result = filmService.update(film);
        if(result >= 1){
            return "更新成功！";
        }else{
            return "更新失败！";
        }
    }

    //插入用户信息
    @RequestMapping(value = "/insert")
    public int insert(Film film){
        return filmService.save(film);
    }

    //查询所有用户的信息
    @RequestMapping(value = "/selectAll")
    @ResponseBody   //理解为：单独作为响应体，这里不调用实体类的toString方法
    public List<Film> listFilm(){
        return filmService.findAll();
    }
}
